package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbUserMapper;
import com.dongdongshop.pojo.TbAdmin;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.pojo.TbUserExample;
import com.dongdongshop.service.UserService;
import com.dongdongsop.util.ShiroUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@DubboService
public class UserServiceImpl implements UserService {

    @Resource
    private TbUserMapper userMapper;

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public int register(TbUser user) {
        String salt = ShiroUtils.generateSalt(6);
        String md5 = ShiroUtils.encryptPassword("MD5", user.getPassword(), salt, 3);
        user.setPassword(md5);
        user.setSalt(salt);
        return userMapper.insertSelective(user);
    }

    @Override
    public void getPhone(String phone) {
        if (!phone.equals(null) || !phone.equals("")){
            rocketMQTemplate.convertAndSend("dongdongshop-sms-topic",phone);
        }
    }

    @Override
    public TbUser getLogin(String username) {
        return userMapper.getLogin(username);
    }
}
